package com.qiankun.tang.ui.view.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.common.library.listener.OnAppListener;
import com.common.library.ui.view.adapter.base.BasePagerAdapter;
import com.qiankun.tang.R;
import com.qiankun.tang.beans.ADBean;
import com.qiankun.tang.ui.view.HorizontalListItemView;

/**
 * @author txf
 * @Title
 * @package com.common.library.ui.view.adapter
 * @date 2017/6/6 0006
 */
public class HorizontalListAdapter extends BasePagerAdapter<ADBean> {
    public HorizontalListAdapter(OnAppListener.OnInteractionListener l) {
        super(l);
    }

    private int getItemType(int position) {
        if (getData() != null && getData().size() > 0)
            return getData().get(position).getType();
        else {
            return -1;
        }
    }
//    SimpleDraweeView img;
//    TextView tvTitle;
//    TextView tvSubTitle;
    @Override
    protected View getView(int position, View contentView, ViewGroup container) {
        int type = getItemType(position);
        switch (type) {
            case 0:
                HorizontalListItemView view = null;
                if (contentView == null) {
                    view = (HorizontalListItemView) LayoutInflater.from(container.getContext()).inflate(R.layout.item_horizontallist_0, null);
                } else {
                    view = (HorizontalListItemView) contentView;
                }
//                img = (SimpleDraweeView) view.findViewById(R.id.item_horizontallist_0_img);
//                tvTitle = (TextView) view.findViewById(R.id.item_horizontallist_0_tvTitle);
//                tvSubTitle = (TextView) view.findViewById(R.id.item_horizontallist_0_tvSubTitle);
                final ADBean bean = getData().get(position);
                view.setData(bean);
//                img.setImageURI(bean.getImgUrl());
//                tvTitle.setText(bean.getTvtitle());
//                tvSubTitle.setText(bean.getTvsubtitle());
                view.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        getListener().onInteraction(0, bean);
                    }
                });
                return view;
        }
        return new View(container.getContext());
    }
}
